Named routes Topic

Instead of navigating to a route based on the URL, a GoRoute can be given a unique name. To configure a named route, use the name parameter:

GoRoute(
   name: 'song',
   path: 'songs/:songId',
   builder: /* ... */,
 ),

To navigate to a route using it's name, call goNamed:

TextButton(
  onPressed: () {
    context.goNamed('song', params: {'songId': 123});
  },
  child: const Text('Go to song 2'),
),

Alternatively, you can look up the location for a name using namedLocation:

TextButton(
  onPressed: () {
    final String location = context.namedLocation('song', params: {'songId': 123});
    context.go(location);
  },
  child: const Text('Go to song 2'),
),

Redirecting to a named route

To redirect to a named route, use the namedLocation API:

redirect: (BuildContext context, GoRouterState state) {
  if (AuthState.of(context).isSignedIn) {
    return context.namedLocation('signIn');
  } else {
    return null;
  }   
},

Classes

GoRoute Get started Configuration Transition animations Named routes
A route that is displayed visually above the matching parent route using the Navigator.
GoRouter Get started Upgrading Configuration Navigation Redirection Web Deep linking Named routes Logging Error handling
The route configuration for the app.